package com.example.leetdemo.finash;

public class Solution1493 {


    public int longestSubarray(int[] nums) {
        int[] dp = new int[nums.length + 1];
        int max = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 1) {
                dp[i + 1] = dp[i] + 1;
                if (i - dp[i] > 0) {
                    max = Math.max(max, dp[i + 1] + dp[i - dp[i] - 1]);
                } else {
                    max = Math.max(max, dp[i] + 1);
                }
            }
        }
        return max;
    }

}
